package com.next

class BootStrap
{
    def init = { servletContext ->

        if (Role.count() < 1)
        {
            println 'init role data'

            def r = new Role()
            r.authority = 'ROLE_ADMINISTRATOR'
            r.description = '系统管理员'
            r.save()

            r = new Role()
            r.authority = 'ROLE_COMPANY_ADMINISTRATOR'
            r.description = '公司管理员'
            r.save()

            r = new Role()
            r.authority = 'ROLE_COMPANY_USER'
            r.description = '公司用户'
            r.save()

            r = new Role()
            r.authority = 'ROLE_COMPANY_CUSTOMER'
            r.description = '公司客户'
            r.save()
        }

        if (AccountType.count() < 1)
        {
            def type = new AccountType(name: "竞争者")
            type.save()

            type = new AccountType(name: "客户")
            type.save()

            type = new AccountType(name: "投资人")
            type.save()

            type = new AccountType(name: "合作伙伴")
            type.save()
        }

        if (AccountLevel.count() < 1)
        {
            def level = new AccountLevel(name: 'A')
            level.save()

            level = new AccountLevel(name: 'B')
            level.save()

            level = new AccountLevel(name: 'C')
            level.save()

            level = new AccountLevel(name: 'D')
            level.save()
        }

        // if (Account.count() < 1)
        // {
        //     def account = new Account(name: "Next Software Co.", type: AccountType.findByName("Partner"))
        //     account.save()
        // }

        if (SecurityProfile.count() < 1)
        {
            def profile = new SecurityProfile(name: "Administrator")
            profile.save()
        }

        if (User.count() < 1)
        {
            println 'init user data'
            def profile = SecurityProfile.findByName("Administrator")
            def c = new User(username: 'ralf', password: '12345678', cellphone: '18513603065', fullName: '尹何栋', securityProfile: profile)
            c.save()
        }

        if (UserRole.count() < 1)
        {
            println 'init user role data'

            UserRole.create(User.findByUsername('ralf'), Role.findByAuthority('ROLE_ADMINISTRATOR'))
        }

        if (TeamRole.count() < 1)
        {
            def tr = new TeamRole(name: "Read")
            tr.save()

            tr = new TeamRole(name: "Edit")
            tr.save()
        }

        if (Territory.count() < 1)
        {
            def territory = new Territory(name: "Default")
            territory.save()

            TerritoryTeam territoryTeam = new TerritoryTeam()
            territoryTeam.startTime = new Date()
            territoryTeam.endTime = new Date()
            territoryTeam.territory = territory
            territoryTeam.user = User.findByUsername("ralf")
            territoryTeam.teamRole = TeamRole.findByName('Edit')
            territoryTeam.contactPermission = TeamRole.findByName('Read')
            territoryTeam.activityPermission = TeamRole.findByName('Read')
            territoryTeam.teamPermission = TeamRole.findByName('Edit')
            territoryTeam.attachmentPermission = TeamRole.findByName('Read')
            territoryTeam.notePermission = TeamRole.findByName('Read')
            territoryTeam.flexFieldPermission = TeamRole.findByName('Read')
            territoryTeam.addressPermission = TeamRole.findByName('Read')
            territoryTeam.save()
        }

        if (OpportunityType.count() < 1)
        {
            def type = new OpportunityType(name: '新业务', code: '01')
            type.save()

            type = new OpportunityType(name: '老业务', code: '02')
            type.save()
        }

        if (OpportunityStage.count() < 1)
        {
            def type = OpportunityType.findByName('新业务')

            def stage = new OpportunityStage(name: '已入围', type: type)
            stage.save()

            stage = new OpportunityStage(name: '需求分析', type: type)
            stage.save()

            stage = new OpportunityStage(name: '解决方案', type: type)
            stage.save()

            stage = new OpportunityStage(name: '谈判', type: type)
            stage.save()

            stage = new OpportunityStage(name: '接近成功', type: type)
            stage.save()

            stage = new OpportunityStage(name: '接近失败', type: type)
            stage.save()
        }

        if (ContactLevel.count() < 1)
        {
            def level = new ContactLevel()
            level.name = "A"
            level.save()

            level = new ContactLevel()
            level.name = "B"
            level.save()

            level = new ContactLevel()
            level.name = "C"
            level.save()

            level = new ContactLevel()
            level.name = "D"
            level.save()
        }

        if (CauseOfFailure.count() < 1)
        {
            def cf = new CauseOfFailure()
            cf.name = "竞争者"
            cf.save()

            cf = new CauseOfFailure()
            cf.name = "预算不够"
            cf.save()

            cf = new CauseOfFailure()
            cf.name = "未决策"
            cf.save()

            cf = new CauseOfFailure()
            cf.name = "价格原因"
            cf.save()

            cf = new CauseOfFailure()
            cf.name = "其它"
            cf.save()
        }

        if (OpportunityContactType.count() < 1)
        {
            def type = new OpportunityContactType(name: "同事")
            type.save()

            type = new OpportunityContactType(name: "配偶")
            type.save()

            type = new OpportunityContactType(name: "父母")
            type.save()

            type = new OpportunityContactType(name: "子女")
            type.save()

            type = new OpportunityContactType(name: "付款审批关键人")
            type.save()
        }

        if (AttachmentType.count() < 1)
        {
            def at = new AttachmentType(name: "合同")
            at.save()
        }

        if (AddressType.count() < 1)
        {
            def type = new AddressType(name: "注册地址")
            type.save()

            type = new AddressType(name: "办公地址")
            type.save()

            type = new AddressType(name: "收货地址")
            type.save()
        }

        if (ActivityType.count() < 1)
        {
            def type = new ActivityType(name: "Appointment")
            type.save()

            type = new ActivityType(name: "Task")
            type.save()

            type = new ActivityType(name: "Call")
            type.save()
        }

        if (ActivitySubtype.count() < 1)
        {
            def subtype = new ActivitySubtype(name: "回访", type: ActivityType.findByName("Appointment"))
            subtype.save()

            subtype = new ActivitySubtype(name: "签约", type: ActivityType.findByName("Appointment"))
            subtype.save()

            subtype = new ActivitySubtype(name: "初次拜访", type: ActivityType.findByName("Appointment"))
            subtype.save()

            subtype = new ActivitySubtype(name: "需求交流", type: ActivityType.findByName("Appointment"))
            subtype.save()

            subtype = new ActivitySubtype(name: "方案沟通", type: ActivityType.findByName("Appointment"))
            subtype.save()

            subtype = new ActivitySubtype(name: "任务", type: ActivityType.findByName("Task"))
            subtype.save()
        }

        if (MessageTemplate.count() < 1)
        {
            def message = new MessageTemplate(text: "Next CRM: 您的联系人 contactName （contactCellphone） 有评房成功商机（serialNumber），请及时关注跟进！")
            message.save()

            message = new MessageTemplate(text: "Next CRM: 您的联系人 contactName（contactCellphone）已提交报单，请及时提供身份证、房产证图片，敬请配合，感谢！")
            message.save()

            message = new MessageTemplate(text: "Next CRM: 您的联系人 contactName （contactCellphone） 已提交报单，请及时关注跟进！")
            message.save()

            message = new MessageTemplate(text: "Next CRM: 商机serialNumber（stage）已分配至您处，请及时处理！")
            message.save()

            message = new MessageTemplate(text: "Next CRM: 您的商机（serialNumber）已失败，失败原因为：causeOfFailure。")
            message.save()
        }

        if (Country.count() < 1)
        {
            def country = new Country(name: '中国')
            country.save()

            country = new Country(name: '台湾')
            country.save()

            country = new Country(name: '香港')
            country.save()

            country = new Country(name: '澳门')
            country.save()

            country = new Country(name: '美国')
            country.save()
        }

        if (Province.count() < 1)
        {
            def country = Country.findByName("中国")

            def province = new Province(name: '北京')
            province.country = country
            province.save()

            province = new Province(name: '天津')
            province.country = country
            province.save()

            province = new Province(name: '上海')
            province.country = country
            province.save()

            province = new Province(name: '重庆')
            province.country = country
            province.save()

            province = new Province(name: '黑龙江')
            province.country = country
            province.save()

            province = new Province(name: '吉林')
            province.country = country
            province.save()

            province = new Province(name: '辽宁')
            province.country = country
            province.save()

            province = new Province(name: '河北')
            province.country = country
            province.save()

            province = new Province(name: '河南')
            province.country = country
            province.save()

            province = new Province(name: '山东')
            province.country = country
            province.save()

            province = new Province(name: '江苏')
            province.country = country
            province.save()

            province = new Province(name: '山西')
            province.country = country
            province.save()

            province = new Province(name: '陕西')
            province.country = country
            province.save()

            province = new Province(name: '甘肃')
            province.country = country
            province.save()

            province = new Province(name: '四川')
            province.country = country
            province.save()

            province = new Province(name: '青海')
            province.country = country
            province.save()

            province = new Province(name: '湖南')
            province.country = country
            province.save()

            province = new Province(name: '湖北')
            province.country = country
            province.save()

            province = new Province(name: '江西')
            province.country = country
            province.save()

            province = new Province(name: '安徽')
            province.country = country
            province.save()

            province = new Province(name: '浙江')
            province.country = country
            province.save()

            province = new Province(name: '福建')
            province.country = country
            province.save()

            province = new Province(name: '广东')
            province.country = country
            province.save()

            province = new Province(name: '广西')
            province.country = country
            province.save()

            province = new Province(name: '贵州')
            province.country = country
            province.save()

            province = new Province(name: '云南')
            province.country = country
            province.save()

            province = new Province(name: '海南')
            province.country = country
            province.save()

            province = new Province(name: '内蒙古')
            province.country = country
            province.save()

            province = new Province(name: '新疆维吾尔族自治区')
            province.country = country
            province.save()

            province = new Province(name: '宁夏回族自治区')
            province.country = country
            province.save()

            province = new Province(name: '西藏')
            province.country = country
            province.save()
        }

        if (City.count() < 1)
        {
            def city = new City(name: '北京')
            city.province = Province.findByName("北京")
            city.save()

            city = new City(name: '天津')
            city.province = Province.findByName("天津")
            city.save()

            city = new City(name: '上海')
            city.province = Province.findByName("上海")
            city.save()

            city = new City(name: '重庆')
            city.province = Province.findByName("重庆")
            city.save()

            city = new City(name: '哈尔滨')
            city.province = Province.findByName("黑龙江")
            city.save()

            city = new City(name: '长春')
            city.province = Province.findByName("吉林")
            city.save()

            city = new City(name: '沈阳')
            city.province = Province.findByName("辽宁")
            city.save()

            city = new City(name: '石家庄')
            city.province = Province.findByName("河北")
            city.save()

            city = new City(name: '郑州')
            city.province = Province.findByName("河南")
            city.save()

            city = new City(name: '济南')
            city.province = Province.findByName("山东")
            city.save()

            city = new City(name: '南京')
            city.province = Province.findByName("江苏")
            city.save()

            city = new City(name: '太原')
            city.province = Province.findByName("山西")
            city.save()

            city = new City(name: '西安')
            city.province = Province.findByName("陕西")
            city.save()

            city = new City(name: '兰州')
            city.province = Province.findByName("甘肃")
            city.save()

            city = new City(name: '成都')
            city.province = Province.findByName("四川")
            city.save()

            city = new City(name: '西宁')
            city.province = Province.findByName("青海")
            city.save()

            city = new City(name: '长沙')
            city.province = Province.findByName("湖南")
            city.save()

            city = new City(name: '武汉')
            city.province = Province.findByName("湖北")
            city.save()

            city = new City(name: '南昌')
            city.province = Province.findByName("江西")
            city.save()

            city = new City(name: '合肥')
            city.province = Province.findByName("安徽")
            city.save()

            city = new City(name: '杭州')
            city.province = Province.findByName("浙江")
            city.save()

            city = new City(name: '福州')
            city.province = Province.findByName("福建")
            city.save()

            city = new City(name: '广州')
            city.province = Province.findByName("广东")
            city.save()

            city = new City(name: '南宁')
            city.province = Province.findByName("广西")
            city.save()

            city = new City(name: '贵阳')
            city.province = Province.findByName("贵州")
            city.save()

            city = new City(name: '昆明')
            city.province = Province.findByName("云南")
            city.save()

            city = new City(name: '海口')
            city.province = Province.findByName("海南")
            city.save()

            city = new City(name: '呼和浩特')
            city.province = Province.findByName("内蒙古")
            city.save()

            city = new City(name: '乌鲁木齐')
            city.province = Province.findByName("新疆维吾尔族自治区")
            city.save()

            city = new City(name: '银川')
            city.province = Province.findByName("宁夏回族自治区")
            city.save()

            city = new City(name: '拉萨')
            city.province = Province.findByName("西藏")
            city.save()
        }

        if (District.count() < 1)
        {
            // 北京区县
            def district = new District()
            district.name = "朝阳区"
            district.city = City.findByName("北京")
            district.save()

            district = new District()
            district.name = "东城区"
            district.city = City.findByName("北京")
            district.save()

            district = new District()
            district.name = "西城区"
            district.city = City.findByName("北京")
            district.save()

            district = new District()
            district.name = "丰台区"
            district.city = City.findByName("北京")
            district.save()

            district = new District()
            district.name = "石景山区"
            district.city = City.findByName("北京")
            district.save()

            district = new District()
            district.name = "海淀区"
            district.city = City.findByName("北京")
            district.save()

            district = new District()
            district.name = "大兴区"
            district.city = City.findByName("北京")
            district.save()

            district = new District()
            district.name = "通州区"
            district.city = City.findByName("北京")
            district.save()

            district = new District()
            district.name = "昌平区"
            district.city = City.findByName("北京")
            district.save()

            district = new District()
            district.name = "房山区"
            district.city = City.findByName("北京")
            district.save()

            district = new District()
            district.name = "顺义区"
            district.city = City.findByName("北京")
            district.save()

            district = new District()
            district.name = "怀柔区"
            district.city = City.findByName("北京")
            district.save()

            district = new District()
            district.name = "密云县"
            district.city = City.findByName("北京")
            district.save()

            district = new District()
            district.name = "平谷区"
            district.city = City.findByName("北京")
            district.save()

            district = new District()
            district.name = "延庆县"
            district.city = City.findByName("北京")
            district.save()

            // 上海区县
            district = new District()
            district.name = "徐汇区"
            district.city = City.findByName("上海")
            district.save()

            district = new District()
            district.name = "普陀区"
            district.city = City.findByName("上海")
            district.save()

            district = new District()
            district.name = "静安区"
            district.city = City.findByName("上海")
            district.save()

            district = new District()
            district.name = "杨浦区"
            district.city = City.findByName("上海")
            district.save()

            district = new District()
            district.name = "黄浦区"
            district.city = City.findByName("上海")
            district.save()

            district = new District()
            district.name = "南汇区"
            district.city = City.findByName("上海")
            district.save()

            district = new District()
            district.name = "嘉定区"
            district.city = City.findByName("上海")
            district.save()

            district = new District()
            district.name = "奉贤区"
            district.city = City.findByName("上海")
            district.save()

            district = new District()
            district.name = "闸北区"
            district.city = City.findByName("上海")
            district.save()

            district = new District()
            district.name = "卢湾区"
            district.city = City.findByName("上海")
            district.save()

            district = new District()
            district.name = "长宁区"
            district.city = City.findByName("上海")
            district.save()

            district = new District()
            district.name = "闵行区"
            district.city = City.findByName("上海")
            district.save()

            district = new District()
            district.name = "青浦区"
            district.city = City.findByName("上海")
            district.save()

            district = new District()
            district.name = "金山区"
            district.city = City.findByName("上海")
            district.save()

            district = new District()
            district.name = "宝山区"
            district.city = City.findByName("上海")
            district.save()

            district = new District()
            district.name = "虹口区"
            district.city = City.findByName("上海")
            district.save()

            district = new District()
            district.name = "浦东新区"
            district.city = City.findByName("上海")
            district.save()

            // 天津区县
            district = new District()
            district.name = "和平区"
            district.city = City.findByName("天津")
            district.save()

            district = new District()
            district.name = "河东区"
            district.city = City.findByName("天津")
            district.save()

            district = new District()
            district.name = "河西区"
            district.city = City.findByName("天津")
            district.save()

            district = new District()
            district.name = "南开区"
            district.city = City.findByName("天津")
            district.save()

            district = new District()
            district.name = "河北区"
            district.city = City.findByName("天津")
            district.save()

            district = new District()
            district.name = "红桥区"
            district.city = City.findByName("天津")
            district.save()

            district = new District()
            district.name = "塘沽区"
            district.city = City.findByName("天津")
            district.save()

            district = new District()
            district.name = "汉沽区"
            district.city = City.findByName("天津")
            district.save()

            district = new District()
            district.name = "大港区"
            district.city = City.findByName("天津")
            district.save()

            district = new District()
            district.name = "天津经济技术开发区"
            district.city = City.findByName("天津")
            district.save()

            district = new District()
            district.name = "天津港保税区"
            district.city = City.findByName("天津")
            district.save()

            district = new District()
            district.name = "天津港"
            district.city = City.findByName("天津")
            district.save()

            district = new District()
            district.name = "东丽区"
            district.city = City.findByName("天津")
            district.save()

            district = new District()
            district.name = "津南区"
            district.city = City.findByName("天津")
            district.save()

            district = new District()
            district.name = "西青区"
            district.city = City.findByName("天津")
            district.save()

            district = new District()
            district.name = "北辰区"
            district.city = City.findByName("天津")
            district.save()

            district = new District()
            district.name = "武清区"
            district.city = City.findByName("天津")
            district.save()

            district.name = "宝坻区"
            district.city = City.findByName("天津")
            district.save()

            district = new District()
            district.name = "静海县"
            district.city = City.findByName("天津")
            district.save()

            district = new District()
            district.name = "宁河县"
            district.city = City.findByName("天津")
            district.save()

            district = new District()
            district.name = "蓟县"
            district.city = City.findByName("天津")
            district.save()

            // 重庆区县
            district = new District()
            district.name = "渝中区"
            district.city = City.findByName("重庆")
            district.save()

            district = new District()
            district.name = "大渡口区"
            district.city = City.findByName("重庆")
            district.save()

            district = new District()
            district.name = "江北区"
            district.city = City.findByName("重庆")
            district.save()

            district = new District()
            district.name = "沙坪坝区"
            district.city = City.findByName("重庆")
            district.save()

            district = new District()
            district.name = "九龙坡区"
            district.city = City.findByName("重庆")
            district.save()

            district = new District()
            district.name = "南岸区"
            district.city = City.findByName("重庆")
            district.save()

            district = new District()
            district.name = "北碚区"
            district.city = City.findByName("重庆")
            district.save()

            district = new District()
            district.name = "綦江区"
            district.city = City.findByName("重庆")
            district.save()

            district = new District()
            district.name = "双桥区"
            district.city = City.findByName("重庆")
            district.save()

            district = new District()
            district.name = "渝北区"
            district.city = City.findByName("重庆")
            district.save()

            district = new District()
            district.name = "巴南区"
            district.city = City.findByName("重庆")
            district.save()

            district = new District()
            district.name = "万州区"
            district.city = City.findByName("重庆")
            district.save()

            district = new District()
            district.name = "涪陵区"
            district.city = City.findByName("重庆")
            district.save()

            district = new District()
            district.name = "黔江区"
            district.city = City.findByName("重庆")
            district.save()

            district = new District()
            district.name = "长寿区"
            district.city = City.findByName("重庆")
            district.save()

            district = new District()
            district.name = "江津区"
            district.city = City.findByName("重庆")
            district.save()

            district = new District()
            district.name = "合川区"
            district.city = City.findByName("重庆")
            district.save()

            district = new District()
            district.name = "永川区"
            district.city = City.findByName("重庆")
            district.save()

            district = new District()
            district.name = "南川区"
            district.city = City.findByName("重庆")
            district.save()
        }

        if (ContractType.count() < 1)
        {
            def contractType = new ContractType(name: '销售合同')
            contractType.save()

            contractType = new ContractType(name: '采购合同')
            contractType.save()
        }

        if (ComponentType.count() < 1)
        {
            def type = new ComponentType(name: 'Condition')
            type.save()

            type = new ComponentType(name: 'Event')
            type.save()

            type = new ComponentType(name: 'System')
            type.save()
        }

        if (WorkflowInstanceStatus.count() < 1)
        {
            def w = new WorkflowInstanceStatus(name: 'Pending')
            w.save()

            w = new WorkflowInstanceStatus(name: 'Completed')
            w.save()

            w = new WorkflowInstanceStatus(name: 'Failed')
            w.save()
        }

        if (WorkflowAuthority.count() < 1)
        {
            def a = new WorkflowAuthority(name: 'View')
            a.save()

            a = new WorkflowAuthority(name: 'Edit')
            a.save()

            a = new WorkflowAuthority(name: 'Approval')
            a.save()
        }

        if (CampaignType.count() < 1)
        {
            def type = new CampaignType(name: '事件')
            type.save()

            type = new CampaignType(name: '试用')
            type.save()

            type = new CampaignType(name: '电子邮件')
            type.save()

            type = new CampaignType(name: '推荐')
            type.save()

            type = new CampaignType(name: '调研')
            type.save()

            type = new CampaignType(name: '社交媒体')
            type.save()
        }

        if (LeadSource.count() < 1)
        {
            def source = new LeadSource(name: '广告')
            source.save()

            source = new LeadSource(name: '客户活动')
            source.save()

            source = new LeadSource(name: '员工推荐')
            source.save()

            source = new LeadSource(name: '百度推广')
            source.save()

            source = new LeadSource(name: '其它')
            source.save()

            source = new LeadSource(name: '合作伙伴')
            source.save()
        }

        if (LeadStatus.count() < 1)
        {
            def status = new LeadStatus(name: '已失败')
            status.save()

            status = new LeadStatus(name: '新机会')
            status.save()

            status = new LeadStatus(name: '跟进中')
            status.save()

            status = new LeadStatus(name: '需求已确认')
            status.save()

            status = new LeadStatus(name: '意见明确')
            status.save()
        }

        if (Salutation.count() < 1)
        {
            def salutation = new Salutation(name: '先生')
            salutation.save()

            salutation = new Salutation(name: '女士')
            salutation.save()

            salutation = new Salutation(name: '总经理')
            salutation.save()

            salutation = new Salutation(name: '总监')
            salutation.save()

            salutation = new Salutation(name: '博士')
            salutation.save()

            salutation = new Salutation(name: '工程师')
            salutation.save()
        }

        if (LeadRating.count() < 1)
        {
            def rating = new LeadRating(name: '热切')
            rating.save()

            rating = new LeadRating(name: '一般')
            rating.save()

            rating = new LeadRating(name: '冷淡')
            rating.save()
        }

        if (Company.count() < 1)
        {
            def company = new Company(name: 'Default', serialNumber: UUID.randomUUID().toString(), enableAccountTerritory: true, enableContactTerritory: true, enableOpportunityTerritory: true)
            company.save()
        }

        if (Industry.count() < 1)
        {
            def industry = new Industry(name: '农业')
            industry.save()

            industry = new Industry(name: '服装业')
            industry.save()

            industry = new Industry(name: '金融业')
            industry.save()

            industry = new Industry(name: '生物科技')
            industry.save()

            industry = new Industry(name: '化工')
            industry.save()

            industry = new Industry(name: '通讯')
            industry.save()

            industry = new Industry(name: 'IT')
            industry.save()
        }

        if (IssueStatus.count() < 1)
        {
            def status = new IssueStatus(name: '新')
            status.save()

            status = new IssueStatus(name: '事态失控')
            status.save()

            status = new IssueStatus(name: '已解决')
            status.save()

            status = new IssueStatus(name: '处理中')
            status.save()
        }

        if (IssueOrigin.count() < 1)
        {
            def origin = new IssueOrigin(name: '电子邮件')
            origin.save()

            origin = new IssueOrigin(name: '电话')
            origin.save()

            origin = new IssueOrigin(name: '网站')
            origin.save()
        }

        if (IssuePriority.count() < 1)
        {
            def priority = new IssuePriority(name: '高')
            priority.save()

            priority = new IssuePriority(name: '中')
            priority.save()

            priority = new IssuePriority(name: '低')
            priority.save()
        }

        if (IssueType.count() < 1)
        {
            def type = new IssueType(name: '投诉')
            type.save()

            type = new IssueType(name: '新需求')
            type.save()

            type = new IssueType(name: '咨询')
            type.save()
        }

        if (IssueReason.count() < 1)
        {
            def reason = new IssueReason(name: "用户未得到有效的培训")
            reason.save()

            reason = new IssueReason(name: '功能太复杂')
            reason.save()

            reason = new IssueReason(name: '老问题')
            reason.save()

            reason = new IssueReason(name: '文件档不清晰')
            reason.save()

            reason = new IssueReason(name: '新问题')
            reason.save()
        }

        if (AssetStatus.count() < 1)
        {
            def status = new AssetStatus(name: '已采购')
            status.save()

            status = new AssetStatus(name: '运输中')
            status.save()

            status = new AssetStatus(name: '已安装')
            status.save()

            status = new AssetStatus(name: '已淘汰')
            status.save()
        }

        if (ContractStatus.count() < 1)
        {
            def status = new ContractStatus(name: '已签订合同')
            status.save()

            status = new ContractStatus(name: '已发货')
            status.save()

            status = new ContractStatus(name: '已验收')
            status.save()

            status = new ContractStatus(name: '已付款')
            status.save()

            status = new ContractStatus(name: '结束')
            status.save()
        }

        if (CampaignStatus.count() < 1)
        {
            def status = new CampaignStatus(name: '计划中')
            status.save()

            status = new CampaignStatus(name: '执行中')
            status.save()

            status = new CampaignStatus(name: '已完成')
            status.save()

            status = new CampaignStatus(name: '已取消')
            status.save()
        }

        if (OpportunityStatus.count() < 1)
        {
            def status = new OpportunityStatus(name: '跟进中')
            status.save()

            status = new OpportunityStatus(name: '已成功')
            status.save()

            status = new OpportunityStatus(name: '已失败')
            status.save()
        }

        if (ContactType.count() < 1)
        {
            def type = new ContactType(name: '日常联系人')
            type.save()

            type = new ContactType(name: '收货人')
            type.save()
        }

        if (Account.count() < 1)
        {
            def account = new Account(name: 'Default', type: AccountType.findByName('客户'), user: User.findByUsername('ralf'))
            if (account.validate())
            {
                account.save()
            }
            else
            {
                account.errors.each {
                    println it
                }
            }
        }

        if (ProductLine.count() < 1)
        {
            def productLine = new ProductLine(name: '服务器')
            productLine.save()

            def product = new Product(name: '联想 X3850', productLine: productLine)
            product.save()

            product = new Product(name: 'DELL R730', productLine: productLine)
            product.save()

            product = new Product(name: 'DELL R930', productLine: productLine)
            product.save()
        }

        if (Department.count() < 1)
        {
            def company = Company.findByName('Default')

            def department = new Department(name: '客服部', active: true, company: company)
            department.save()

            department = new Department(name: '市场部', active: true, company: company)
            department.save()

            department = new Department(name: '销售部', active: true, company: company)
            department.save()

            department = new Department(name: '财务部', active: true, company: company)
            department.save()
        }

        if (FlexFieldCategory.count() < 1)
        {
            def flexFieldCategory = new FlexFieldCategory(name: "IT资产", objectType: "Opportunity")
            flexFieldCategory.save()

            flexFieldCategory = new FlexFieldCategory(name: "付款天数", objectType: "Opportunity")
            flexFieldCategory.save()
        }

        if (FlexField.count() < 1)
        {
            def flexFieldCategory = FlexFieldCategory.findByName("IT资产")

            def flexField = new FlexField(category: flexFieldCategory, name: "桌面保有量", description: "桌面保有量", dataType: "Integer", displayOrder: 0)
            flexField.save()

            flexField = new FlexField(category: flexFieldCategory, name: "企业级保有量", description: "企业级保有量", dataType: "Integer", displayOrder: 1)
            flexField.save()

            flexField = new FlexField(category: flexFieldCategory, name: "每年资产更新率", description: "每年资产更新率", dataType: "String", displayOrder: 2)
            flexField.save()

            flexField = new FlexField(category: flexFieldCategory, name: "企业使用业务系统", description: "企业使用业务系统", dataType: "String", displayOrder: 3)
            flexField.save()

            flexField = new FlexField(category: flexFieldCategory, name: "IT采购目的", description: "IT采购目的", dataType: "String", displayOrder: 4)
            flexField.save()

            flexField = new FlexField(category: flexFieldCategory, name: "IT团队人数", description: "IT团队人数", dataType: "Integer", displayOrder: 5)
            flexField.save()

            flexField = new FlexField(category: flexFieldCategory, name: "运维人数", description: "运维人数", dataType: "Integer", displayOrder: 6)
            flexField.save()

            flexField = new FlexField(category: flexFieldCategory, name: "研发团队人数", description: "研发团队人数", dataType: "Integer", displayOrder: 7)
            flexField.save()

            flexField = new FlexField(category: flexFieldCategory, name: "对外运营的服务平台", description: "对外运营的服务平台", dataType: "String", displayOrder: 8)
            flexField.save()

            flexField = new FlexField(category: flexFieldCategory, name: "竞争品牌保有量", description: "竞争品牌保有量", dataType: "Integer", displayOrder: 9)
            flexField.save()


            flexFieldCategory = FlexFieldCategory.findByName("付款天数")

            flexField = new FlexField(category: flexFieldCategory, name: "发货-收货", description: "发货-收货", dataType: "Integer", displayOrder: 0)
            flexField.save()

            flexField = new FlexField(category: flexFieldCategory, name: "收货-验收", description: "收货-验收", dataType: "Integer", displayOrder: 1)
            flexField.save()

            flexField = new FlexField(category: flexFieldCategory, name: "验收-开发票", description: "验收-开发票", dataType: "Integer", displayOrder: 2)
            flexField.save()

            flexField = new FlexField(category: flexFieldCategory, name: "开发票-申请付款", description: "开发票-申请付款", dataType: "Integer", displayOrder: 3)
            flexField.save()

            flexField = new FlexField(category: flexFieldCategory, name: "申请付款-实际付款", description: "申请付款-实际付款", dataType: "Integer", displayOrder: 4)
            flexField.save()

            flexField = new FlexField(category: flexFieldCategory, name: "特殊要求", description: "特殊要求", dataType: "String", displayOrder: 5)
            flexField.save()
        }

        if (FlexFieldValue.count() < 1)
        {
            def flexField = FlexField.findByName("企业使用业务系统")

            def flexFieldValue = new FlexFieldValue(field: flexField, value: "SAP/ORACLE", displayOrder: 0)
            flexFieldValue.save()

            flexFieldValue = new FlexFieldValue(field: flexField, value: "VM", displayOrder: 1)
            flexFieldValue.save()

            flexFieldValue = new FlexFieldValue(field: flexField, value: "OA系统", displayOrder: 2)
            flexFieldValue.save()

            flexFieldValue = new FlexFieldValue(field: flexField, value: "企业邮箱", displayOrder: 3)
            flexFieldValue.save()

            flexFieldValue = new FlexFieldValue(field: flexField, value: "数据中心类型（自建、租用）", displayOrder: 4)
            flexFieldValue.save()

            flexFieldValue = new FlexFieldValue(field: flexField, value: "公有云（自建、租用）", displayOrder: 5)
            flexFieldValue.save()



            flexField = FlexField.findByName("IT采购目的")

            flexFieldValue = new FlexFieldValue(field: flexField, value: "自用", displayOrder: 0)
            flexFieldValue.save()

            flexFieldValue = new FlexFieldValue(field: flexField, value: "项目采购", displayOrder: 1)
            flexFieldValue.save()
        }

        if (PurchasingMethod.count() < 1)
        {
            def pm = new PurchasingMethod(name: "招标")
            pm.save()

            pm = new PurchasingMethod(name: "自采")
            pm.save()

            pm = new PurchasingMethod(name: "央采")
            pm.save()

            pm = new PurchasingMethod(name: "三方比价")
            pm.save()
        }

        if (CurrencyType.count() < 1)
        {
            def type = new CurrencyType(name: '人民币')
            type.save()

            type = new CurrencyType(name: '美元')
            type.save()
        }
    }

    def destroy = {}
}
